package com.sgj.vo;

import com.sgj.enums.RespBeanEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 公共返回类
 * @author 沈国纪
 * @date 2021/1/15 10:23
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespBean {

    /**
     * 错误码
     */
    private long code;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 传输内容
     */
    private Object data;


    /**
     * 成功返回结果
     * @return
     */
    public static RespBean success () {
        return new RespBean(RespBeanEnum.SUCCESS.getCode(), RespBeanEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 成功返回结果
     * @param data
     * @return
     */
    public static RespBean success (Object data) {
        return new RespBean(RespBeanEnum.SUCCESS.getCode(), RespBeanEnum.SUCCESS.getMessage(), data);
    }

    /**
     * 失败返回结果
     * @param respBeanEnum
     * @return
     */
    public static RespBean error (RespBeanEnum respBeanEnum) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMessage(), null);
    }

    /**
     * 失败返回结果
     * @param respBeanEnum
     * @param data
     * @return
     */
    public static RespBean error (RespBeanEnum respBeanEnum, Object data) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMessage(), data);
    }
}
